package Persistence;

/**
 * The persistence controller
 * 
 * @author kenneth
 */
public class PersistenceController {
    
    private final DatabaseConnection databaseConnection;
    private final UserMapper userMapper;
    private static PersistenceController instance;
    
    private PersistenceController() {
        databaseConnection = new DatabaseConnection();
        userMapper = new UserMapper(databaseConnection);
    }
    
    /**
     * Singleton pattern, so there is only 1 database connection
     * 
     * @return The persistencecontroller instance
     */
    public static PersistenceController getInstance() {
        if(instance == null)
            instance = new PersistenceController();
        return instance;
    }
    
    /**
     * Asks the user mapper if the email & password are correct
     *
     * @param email The email address of the user
     * @param password The password of the user
     * @return True if correct
     */
    public boolean authenticateUser(String email, String password) {
        return userMapper.authenticateUser(email, password);
    }
    
    /**
     * Asks the user mapper to register a user with the server
     * 
     * @param email The email address of the user
     * @param password The password of the user
     * @return True if the registration succeeded
     */
    public boolean registerUser(String email, String password) {
        return userMapper.registerUser(email, password);
    }
    
    /**
     * Asks the user mapper to resets the password from a user
     * 
     * @param email The email address of the user
     * @return True if the password reset succeeded
     */
    public boolean resetPasswordFromUser(String email) {
        return userMapper.resetPasswordFromUser(email);
    }

}
